package es.ubu.mascaras;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;

public class emailVerifier extends InputVerifier{

	@Override
	public boolean verify(JComponent field) {
		JFormattedTextField jftf= (JFormattedTextField) field;
		Pattern pattern = Pattern.compile("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+[.][a-zA-Z]{2.6}");
		Matcher matcher= pattern.matcher(jftf.getText());
		if(!matcher.find()&& jftf.getText().length()!=0){
			javax.swing.JOptionPane.showMessageDialog(field, "El formato es incorrecto");
			return false;
		} else{
			return true;
		}
	}

}
